home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ProcessHelpers.c
-
- Contains: Functions to help you when working with processes.
-
- Written by: Andy Bachorski
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/21/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- //******************************************************************************
- // A private conditionals file to setup the build environment for this project.
-
- #include "PrivateConditionals.h"
-
-
- //********** Universal Headers ****************************************
-
- #include <Processes.h>
- #include <Types.h>
-
-
- //********** Project Headers ****************************************
-
- #include "ProcessHelpers.h"
-
-
- //******************************************************************************
-
- pascal OSErr FindProcessBySignature( const OSType targetType,
- const OSType targetCreator,
- ProcessSerialNumberPtr psnPtr )
- {
- OSErr anErr = noErr;
- Boolean lookingForProcess = true;
-
- ProcessInfoRec infoRec;
-
- infoRec.processInfoLength = sizeof( ProcessInfoRec );
- infoRec.processName = nil;
- infoRec.processAppSpec = nil;
-
- psnPtr->lowLongOfPSN = kNoProcess;
- psnPtr->highLongOfPSN = kNoProcess;
-
- while ( lookingForProcess )
- {
- anErr = GetNextProcess( psnPtr );
- if ( anErr != noErr )
- {
- lookingForProcess = false;
- }
- else
- {
- anErr = GetProcessInformation( psnPtr, &infoRec );
- if ( ( anErr == noErr )
- && ( infoRec.processType == targetType )
- && ( infoRec.processSignature == targetCreator ) )
- {
- lookingForProcess = false;
- }
- }
- }
-
- return anErr;
- }//end FindProcessBySignature
-
- //******************************************************************************
-
- pascal OSErr GetProcessName( const ProcessSerialNumberPtr psnPtr,
- StringPtr processName )
- {
- OSErr anErr = noErr;
- ProcessInfoRec infoRec;
-
- infoRec.processInfoLength = sizeof( ProcessInfoRec );
- infoRec.processName = processName;
- infoRec.processAppSpec = nil;
-
- anErr = GetProcessInformation( psnPtr, &infoRec );
-
- return anErr;
- }//end FindProcessBySignature
-
- //******************************************************************************
-
- pascal OSErr GetProcessTypeSignature( const ProcessSerialNumberPtr psnPtr,
- OSType *processType,
- OSType *processSignature )
- {
- OSErr anErr = noErr;
- ProcessInfoRec infoRec;
-
- infoRec.processInfoLength = sizeof( ProcessInfoRec );
- infoRec.processName = nil;
- infoRec.processAppSpec = nil;
-
- anErr = GetProcessInformation( psnPtr, &infoRec );
- if ( anErr == noErr )
- {
- *processType = infoRec.processType;
- *processSignature = infoRec.processSignature;
- }
-
- return anErr;
- }//end FindProcessBySignature
-
- //******************************************************************************
-
- // Return an FSSpec to the current process
-
- pascal OSErr GetCurrentProcessFSSpec( FSSpec *spec )
- {
- ProcessSerialNumber currentPSN;
- ProcessInfoRec info;
-
- /* Get the current process' FSSpec with GetProcessInformation */
- currentPSN.highLongOfPSN = 0;
- currentPSN.lowLongOfPSN = kCurrentProcess;
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = NULL; /* we don't need the process name */
- info.processAppSpec = spec;
- return ( GetProcessInformation(¤tPSN, &info) );
- }
-
- //******************************************************************************
-